<script lang="ts" setup>
// 首页主体，新鲜好物
import HomePanel from './home-panel.vue'
import useStore from '@/store'
import { apiLazy } from '@/utils/hooks'
import { defineAsyncComponent } from 'vue'
const { home } = useStore()
const target = apiLazy(home.homeNew)
const homeSkeleton = defineAsyncComponent(() => import('./home-skeleton.vue'))
// home.homeNew()
</script>
<template>
  <div class="home-new" ref="target">
    <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
      <template #right><XtxMore path="/"/></template>
      <!-- 
        动画
        vue2:
            .xxx-enter-active  进入时执行的动画效果，进入时一直存在
            .xxx-enter  想要从什么状态到正常状态
            .xxx-leave-active  离开时执行的动画，离开时一直存在
            .xxx-leave-to  想要从正常状态到什么状态
        vue3:
            .xxx-enter-active  进入时执行的动画效果，进入时一直存在
            .xxx-enter-from  想要从什么状态到正常状态
            .xxx-leave-active  离开时执行的动画，离开时一直存在
            .xxx-leave-to  想要从正常状态到什么状态
       -->
      <div class="view">
        <transition name="fade">
          <!-- 面板内容 -->
          <ul class="goods-list" v-if="home.newList.length">
            <li :key="item.id" v-for="item in home.newList">
              <RouterLink to="/">
                <img v-lazyImg="item.picture" alt="" />
                <p class="name ellipsis">{{ item.name }}</p>
                <p class="price">&yen;{{ item.price }}</p>
              </RouterLink>
            </li>
          </ul>
          <homeSkeleton v-else />
        </transition>
      </div>
    </HomePanel>
  </div>
</template>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
.home-skeleton {
  width: 1240px;
  height: 406px;
  display: flex;
  justify-content: space-between;
  .item {
    width: 306px;
    .xtx-skeleton ~ .xtx-skeleton {
      display: block;
      margin: 16px auto 0;
    }
  }
}

.view {
  position: relative;
}
// 动画
.xxx {
  &-enter {
    &-active {
      transition: all 0.5s;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
    }
    &-from {
      opacity: 0;
    }
  }
  &-leave {
    &-active {
      transition: all 0.5s;
    }
    &-to {
      opacity: 0;
    }
  }
}
</style>
